﻿package net.jmp0.toast.levels 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.FileReference;
	import net.jmp0.toast.entities.bases.GameButton;
	import net.jmp0.toast.entities.effects.GameText;
	import net.jmp0.toast.entities.menu.CreditsButton;
	import net.jmp0.toast.entities.menu.PasswordButton;
	import net.jmp0.toast.entities.menu.StartButton;
	import net.jmp0.toast.entities.menu.TitleText;
	import net.jmp0.toast.entities.menu.WhatButton;
	import punk.Backdrop;
	import punk.core.Spritemap;
	import punk.core.World;

	
	/**
	 * ...
	 * @author Thodd
	 */
	public class MainMenu extends World
	{
		//Background
		[Embed(source = '../res/karosheet.png')]private var imgBackgroundKaro:Class;
		private var backgroundKaro:Backdrop = new Backdrop(imgBackgroundKaro, 0, 0, true, true);
		[Embed(source = '../res/coffee_stain_splash.png')]private var imgBackgroundStainSplash:Class;
		private var backgroundStainSplash:Backdrop = new Backdrop(imgBackgroundStainSplash, 0, 0, false, false);
		[Embed(source = '../res/coffee_stain_big.png')]private var imgBackgroundStainBig:Class;
		private var backgroundStainBig:Backdrop = new Backdrop(imgBackgroundStainBig, 0, 0, false, false);
		
		//fonts
		[Embed(source = '../res/take_out_the_garbage.ttf', fontFamily = 'garbage')] private var fontGarbage:Class;
		[Embed(source = '../res/Kraboudja.ttf', fontFamily = 'kraboudja')] private var fontKraboudja:Class;

		public function MainMenu() {
		
		}
		
		
		/**
		 * Initialising the Level
		 */
		override public function init():void {
			
			//Background setup
			setupBackgroundDecals();
			
			//title text
			this.add(new TitleText());
			
			//The buttons of the main menu
			this.add(new StartButton(230, 150, startButtonPressed));
			this.add(new WhatButton(235, 220, whatButtonPressed));
			this.add(new PasswordButton(220, 280, passwordButtonPressed));
			this.add(new CreditsButton(245, 390, creditsButtonPressed));
			
			//cursor
			this.add(new MainMenuCursor());
			
			//loading up the singletons
			LevelTracker.getInstance();
			
		}
		
		/**
		 * This function is executed when the start button is pressed
		 * @param	caller a reference to the start button object which is calling this method
		 */
		private function startButtonPressed(caller:GameButton):void {
			trace("start was clicked");
			//Calling the LevelTracker for the first time and starting the first level
			LevelTracker.getInstance().switchToLevel(LevelTracker.getInstance().next());
		}
		
		/**
		 * This function is executed when the what button is pressed
		 * @param	caller a reference to the what button object which is calling this method
		 */
		private function whatButtonPressed(caller:GameButton):void {
			LevelLoader.getInstance().loadLevelList();
			trace("load was clicked");
		}
		
		/**
		 * yadda yadda
		 * @param	caller look above
		 */
		private function creditsButtonPressed(caller:GameButton):void {
			trace("credits was clicked :O");
		}
		
		/**
		 * same as before
		 * @param	caller boooring
		 */
		private function passwordButtonPressed(caller:GameButton):void {
			trace("password was clicked :D");
			
			FP.goto = new PasswordScreen();
			
			/*var lvl:XML = LevelTracker.getInstance().findLevelByPassword("key");
			if(lvl != null){
				LevelTracker.getInstance().switchToLevel(lvl);
			}*/
		}
		
	
		/**
		 * Just setting up some coffee stain "decals"
		 */
		private function setupBackgroundDecals():void {
			FP.screen.color = 0xFFFFFF;
			backgroundKaro.depth = 100000;
			backgroundStainSplash.depth = 10000;
			backgroundStainBig.depth = 10000;
			
			backgroundStainSplash.x = -112;
			backgroundStainSplash.y = 160;
			
			backgroundStainBig.x = 464;
			backgroundStainBig.y = -128;
			
			this.add(backgroundKaro);
			this.add(backgroundStainSplash);
			this.add(backgroundStainBig);
		}
		
		
	}

}